package conchmusic.conchmusicclient.util;

import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import conchmusic.conchmusicclient.pojo.Song;

/**
 * Created by Administrator on 2017/4/15.
 */

public class ScanMusic {
    private List<Song> localMusics;
    public List<Song> query(Context mContext){
        localMusics=new ArrayList<Song>();
        Cursor cursor=mContext.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null,null, null,
                MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
        if(cursor!=null){
            while (cursor.moveToNext()){
                String songName=cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
                String singer=cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
                String songPath=cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
                String album=cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
                int size=cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
                Log.i("ScanMusic",Integer.toString(size));
                Song song=new Song();
                List<String> artistName=new ArrayList<>();
                List<Integer> artistId=new ArrayList<>();
                artistId.add(0);
                artistName.add(singer);
                song.setTitle(songName);
                song.setArtistNames(artistName);
                song.setAlbumName(album);
                song.setLocalSongUrl(songPath);
                song.setArtistIds(artistId);
                song.setLocalPictureUrl("");;
                song.setLocalLyricUrl("");
                if(size>120000){
                    localMusics.add(song);
                }
            }
            cursor.close();
        }
        return localMusics;
    }

}
